#!/usr/bin/python3
# ******************************************************************************
# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
# licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#     http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# ******************************************************************************/
"""
marshmallow class
"""

from marshmallow import Schema, pre_load
from marshmallow import fields
from marshmallow import validate


class StartSchema(Schema):
    """[summary]

    Args:
        Schema ([type]): [description]
    """

    issueid = fields.String(required=True, validate=validate.Length(min=1))
    giteeid = fields.String(required=True, validate=validate.Length(min=1))
    repo = fields.String(required=True, validate=validate.Length(min=1))
    # comment = fields.String(required=True, validate=validate.Length(min=1))


class CheckSchema(Schema):
    """[summary]
    CheckSchema
    Args:
        Schema ([type]): [description]
    """

    issueid = fields.String(required=True, validate=validate.Length(min=1))
    giteeid = fields.String(required=True, validate=validate.Length(min=1))
    type = fields.String(required=True, validate=validate.OneOf(['status', 'requires', 'test']))
    # result = fields.String(required=False, validate=validate.OneOf(["yes", "no", ""]))


class ModifySchema(Schema):
    """
    ModifySchema
    """

    issueid = fields.String(required=True, validate=validate.Length(min=1))
    giteeid = fields.String(required=True, validate=validate.Length(min=1))
    id = fields.List(fields.String(), validate=validate.Length(min=1))
    choice = fields.String(required=True, validate=validate.OneOf(["cve", "bugfix", "remain"]))
    # choice = fields.String(required=True, validate=validate.OneOf([]))

    # @pre_load
    # def _update_choice(self, data, **kwargs):
    #     """
    #     update_paramter
    #     Args:
    #         data: parameter
    #     Returns:
    #         data: Parameters after processing
    #     """
    #
    #     if data.get('choice'):
    #         self.__dict__["load_fields"]["act"] = \
    #             fields.String(required=True, validate=validate.OneOf(["yes", "no"]))
    #
    #     return data


class ReleaseSchema(Schema):
    """
    ReleaseSchema
    """
    issueid = fields.String(required=True, validate=validate.Length(min=1))
    giteeid = fields.String(required=True, validate=validate.Length(min=1))
    type = fields.String(required=True, validate=validate.OneOf(["checkok", "cvrfok"]))